// ignore_for_file: avoid_print
import 'package:web_socket_client/web_socket_client.dart';

void main() async {
  // Create a WebSocket client.
  final uri = Uri.parse('ws://localhost:8082');
  // final uri = Uri.parse('ws://10.0.0.8:19999/wss/bridging');
  // const backoff = ConstantBackoff(Duration(seconds: 1));
  final backoff = LinearBackoff(initial: Duration(seconds: 1),increment: Duration(seconds: 2));
  final socket = WebSocket(uri, backoff: backoff,timeout: Duration(seconds: 3));

  // Listen for changes in the connection state.
  socket.connection.listen((ConnectionState state) {
    print('state: "$state"');
    print('${state == Connected()}');
    if (state == Connected()) {
      socket.send('hello world');
    }
  });

  // Listen for incoming messages.
  socket.messages.listen((message) {
    print('message: "$message"');
  });

  // await Future<void>.delayed(const Duration(seconds: 30));

  // Close the connection.
  // socket.close();
}
